package com.woniuxy.amusementparkos.util.lzw.src;

import com.sun.org.apache.xpath.internal.operations.String;
import weka.associations.Apriori;
import weka.associations.FPGrowth;
import weka.core.Instances;
import weka.core.converters.ArffSaver;
import weka.core.converters.CSVLoader;

import java.io.*;

/**
 * @author lizhiwen
 * @create 2020-05-01 1:55 上午
 */
public class SupermarketUtil {

    public static void main(String[] args) throws Exception {

        CSVLoader loader = new CSVLoader();
        loader.setFieldSeparator(",");
        loader.setSource(new File("src/main/java/com/woniuxy/amusementparkos/util/lzw/data/CAT.csv"));
        loader.setNominalAttributes("1");
        Instances data = loader.getDataSet();
        for (int i = 0; i <10 ; i++) {
            data.renameAttribute(i, "X"+(i+1));
        }
        // 转为arff
        ArffSaver saver = new ArffSaver();
        saver.setInstances(data);
        saver.setFile(new File("src/main/java/com/woniuxy/amusementparkos/util/lzw/data/CAT.arff"));
        saver.writeBatch();

        // load data
//        Instances data = new Instances(new BufferedReader(new FileReader("src/main/java/com/woniuxy/amusementparkos/util/lzw/data/CAT.arff")));
//        // build model
//        Apriori model = new Apriori();
//        model.buildAssociations(data);
//        System.out.println(model);
//
//        FPGrowth fpgModel = new FPGrowth();
//        fpgModel.setNumRulesToFind(1);
//        fpgModel.buildAssociations(data);
//        System.out.println(fpgModel);
    }

}
